class Image < ActiveRecord::Base
  belongs_to :ecase
  belongs_to :author, :class_name => "User", :foreign_key => "author_id"
  validates_presence_of :ecase_id, :url, :author_id  
  validates_format_of :url, 
    :with => %r{\.(gif|jpg|png|swf|zip)$}i,
    :message => "must point to GIF, JPG, PNG, SWF or ZIP file"
  file_column :url
  
  def category
    ResourceCategory::IMAGE
  end
  
  def name
    read_attribute(:url).split("/").last
  end
end